/**
 * 系统公告管理初始化
 */
var Proclamation = {
    id: "ProclamationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Proclamation.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '类型 0 最新通知 1公告', field: 'type', visible: true, align: 'center', valign: 'middle'},
            {title: '标题', field: 'title', visible: true, align: 'center', valign: 'middle'},
            {title: '内容', field: 'content', visible: true, align: 'center', valign: 'middle'},
            {title: '状态 0 启动 1禁用', field: 'status', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Proclamation.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Proclamation.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加系统公告
 */
Proclamation.openAddProclamation = function () {
    var index = layer.open({
        type: 2,
        title: '添加系统公告',
        area: ['80%', '80%'], //宽高
        fix: false, //不固定
        maxmin: false,
        content: Feng.ctxPath + '/proclamation/proclamation_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看系统公告详情
 */
Proclamation.openProclamationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '系统公告详情',
             area: ['80%', '80%'], //宽高
            fix: false, //不固定
            maxmin: false,
            content: Feng.ctxPath + '/proclamation/proclamation_update/' + Proclamation.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除系统公告
 */
Proclamation.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/proclamation/delete", function (data) {
            Feng.success("删除成功!");
            Proclamation.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("proclamationId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询系统公告列表
 */
Proclamation.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Proclamation.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Proclamation.initColumn();
    var table = new BSTable(Proclamation.id, "/proclamation/list", defaultColunms);
    table.setPaginationType("client");
    Proclamation.table = table.init();
});
